Method and apparatus for data compression and gray value estimation

ABSTRACT

A method and apparatus for compression of data. The invention provides for the application of a plurality of compression schemes to the data such that improved compression ratios are achieved. A first embodiment provides for compression of each pixel by one of a plurality of different entropy-based compression schemes based upon a probability cost analysis. A second embodiment provides for compression of each pixel based on a hybrid context formed using a plurality of compression schemes for improved probability determination, and thus improved entropy encoding. In embodiments of the invention, a context compression scheme similar to JBIG is applied, as well as an inverse scheme. The context scheme forms a statistical context from a concatenated sequence of previous pixel values. The inverse scheme provides a gray value estimation method based upon previous pixel values and respective threshold values. Statistics are maintained with respect to the actual current pixel value and the difference between an estimated gray value and the current pixel threshold value.

BACKGROUND OF THE INVENTION

1. Field of the Invention

This invention relates to the field of compression and decompression ofdata.

2. Background Art

Information is represented in a computer system by binary data in theform of 1s and 0s. This binary data is often maintained in a datastorage device. In a computer system, data storage is a limitedresource. To more efficiently use data storage resources, data is oftencompressed prior to storage so that less storage area is required. Whenthe data is retrieved, it is decompressed for use. The need forcompression can be demonstrated by describing the way that images arerepresented in a computer system, the transformation of such images intoa form suitable for printing, and the storage problems associated withsuch images. This discussion is followed by descriptions of compressiontechniques and prior art approaches to compression.

If a person were to look closely at a television screen, computerdisplay, magazine page, etc., he would see that an image is made up ofhundreds or thousands of tiny dots, where each dot is a different color.These dots are known as picture elements, or "pixels," when they are ona computer display and as dots when printed on a page. The color of eachpixel is represented by a number value. To store an image in a computermemory, the number value of each pixel of the picture is stored. Thenumber value typically represents the color and intensity of the pixel.

The accuracy with which a document can be reproduced is dependent on the"resolution" of the pixels that make up the document. The resolution ofa pixel is determined by the range of the number value used to describethat pixel. The range of the number value is limited by the number of"bits" in the memory available to describe each pixel (a bit is a binarynumber having a value of 1 or 0). The greater the number of bitsavailable per pixel, the greater the resolution of the document. Forexample, when only one bit per pixel is available for storage, only twovalues are available for the pixel. If two bits are available, fourlevels of color or intensity are available. While greater resolution isdesirable, it can lead to greater use of data storage. For example, ifeach pixel is represented by a 32-bit binary number, 320,000 bits ofinformation would be required to represent a 100×100 pixel image. Suchinformation is stored in what is referred to as a "Frame Buffer" or grayarray ("G array").

A black and white printer has resolution of only one bit per pixel ordot. That is, the printer is only capable of printing a black dot at alocation or of leaving the location blank. When an image is to beprinted on a black and white printer, the image must be transformed sothat its bit resolution matches the bit resolution of the printer. Thistransformation is known as "thresholding" and consists of determining,for each pixel in the source image, whether the dot to be printed at thecorresponding location on the printed page is to be black or white.

Although the printer can only do black and white printing, a printedimage can appear to have many different shades of gray depending on thepattern of black and white dots. When every other dot is black, forexample, the resulting printed image will appear gray, because the humaneye blends the tiny dots together. Many printers are capable of printing600 dots per inch in the horizontal and vertical directions. Because ofthe large number of tiny dots, other shades of gray can be simulated bythe relative percentage of black and white dots in any region. The moreblack dots in a region, the darker that region appears.

As noted above, when thresholding, a decision is made for each pixel,based on its original color in the source image, of whether to print ablack or white dot on the page for that pixel. Consider a thresholdingscheme where each pixel in the stored grayscale image may be representedby 8 bits, for example, giving 256 (2⁸) possible values. Onethresholding method that does not produce very realistic images is toassign a black value to all image pixels with a value of 128 (out of256) or above, and a white value to all image pixels with a value of 127or below. Using thresholding, an entire multi-bit depth frame buffer canbe compressed into a one bit per pixel buffer. However, the resultingimage is "aliased" (appears like steps or contains jagged edges) anddoes not approximate the original image. To produce better images, athreshold matrix is generated and used to determine the thresholdedvalue of an image pixel.

A threshold matrix uses different threshold values for an image pixel,depending on the address of the image pixel in the array. Thus, eachcell of the frame buffer corresponds to a threshold matrix cell whichhas an independent threshold level. The threshold matrix need not be thesame size and is often smaller than the G array. For example, at onelocation, an image pixel may be thresholded to black if its value is 128or above, while an image pixel at another location may be black only ifits value is 225 or higher. The result of applying the threshold matrixis an array of 1s and 0s that could be printed to represent the originalcontinuous tone image.

FIG. 1A depicts a frame buffer (G array), with indices i and j(G.sub.[i][j]). FIG. 1B depicts a threshold matrix (T array), withindices i' and j' (T.sub.[i'][j']). FIG. 1C depicts the resulting outputor pixel array (P array) with i rows and j columns (P.sub.[j'][j']).Thus, for example, if the pixel maintains a value of 123 (G₁₁ of FIG.1A) and the threshold level is 128 (T₁₁ of FIG. 1B), the resulting valueis 0 (P₁₁ of FIG. 1C) due to the fact that the pixel value is less thanthe threshold level. Hence the resulting pixel array is created bythresholding the G array as follows: ##EQU1## where G[i][j] is an arrayof the same dimensions as P but takes on many values, typically 0,1, . .. ,255. T[i'][j'] is a threshold array, a matrix of dimension nthreshold rows by m threshold columns and taking on values in a rangelike G, typically 1,2, . . . ,255. For the thresholding (i',j') is afunction of (i,j) typically:

    i'=i modulo n

    j'=j modulo m

where modulo means the remainder after division.

After this thresholding step, the entire page can be represented in amemory of 1s and 0s by the same number of bits as there are dots on thepage. Even at 1 bit per dot, the amount of memory required can besubstantial. For a page that is 8.5 by 11 inches and has a resolution of600 dots per inch (dpi), the amount of memory needed is approximately4.2 megabytes of memory (if monochrome). This memory in a printer isreferred to as a "buffer". Memory is an expensive component, and it isan advantage to reduce the amount of memory required in a printerbuffer. In the past, this has been accomplished by applying a"compression algorithm" to the data in the buffer. Despite thesignificant compression which may arise from thresholding, furthercompression is desired.

There are currently compression schemes for single bit data. Some ofthese schemes work preferentially better on data that was originallytext and some work better on data that was originally an image. Some ofthese schemes include facsimile standards, such as the ITU standards,using Huffman encoded run lengths and the JBIG (Joint Bi-level ImageGroup) standard.

There are two distinct families of prior art compression schemes: lossyand lossless. Lossless compression guarantees that no data will be lostupon a compression and decompression sequence. For example, one losslesscompression scheme accomplishes this guarantee by searching the data forany repeating sequences such as "001001001001001001". Using thislossless compression scheme, the sequence "001" would be stored alongwith the number of times it recurs--six. However, lossless compressionschemes may not provide a satisfactory level of compression, e.g., dueto the absence of repeating sequences in the source data for the aboveexample. Nonetheless, due to its accuracy, lossless compression is usedwhen storing database records, spreadsheets, or word processing files.

A lossy scheme achieves a greater level of compression while risking aloss of a certain amount of accuracy. However, certain types of storedinformation do not require perfect accuracy, such as graphics images anddigitized voice. As a result, lossy compression is often utilized onsuch types of information.

The most interesting prior art method is set forth in the JBIG standard.Pixels are processed in the usual scan order, i.e., row_(i) is entirelyprocessed before row_(i+1) and in each row, column_(i) precedescolumn_(i+1). Encoding the current pixel uses a context, which comprisesa set of nearby pixels that have already been encoded. If, e.g., tenpixels were used as a neighborhood, there would be 2¹⁰ possiblecontexts. Based on the frequency with which the current context has beenpreviously encountered, the encoder makes a prediction and estimates theprobability that the prediction is accurate. If the estimatedprobability is reliable and near to certainty, then an arithmeticentropy encoder can losslessly encode the prediction error (e.g., 0 forno error, 1 for error) with much less than 1 bit per pixel. The decoderhas the same context and frequency information, and is therefore able tointerpret the 0 or 1 to determine the true value of the pixel.

See also U.S. Pat. No. 5,442,458, issued to Rabbani et al., which isdirected to an encoding method for image bitplanes using conditioningcontexts based on pixels from the current and previous bitplanes.

SUMMARY OF THE INVENTION

The present invention provides a method and apparatus for compression ofdata. Whereas the performance of compression schemes of the prior artare often dependent on the type of data being compressed, the inventionprovides for the application of a plurality of compression schemes tothe data such that improved compression ratios are achieved. A firstembodiment provides for compression of each pixel by one of a pluralityof different entropy-based compression schemes based upon a probabilitycost analysis. A second embodiment provides for compression of eachpixel based on a hybrid context formed using a plurality of compressionschemes for improved probability determination, and thus improvedentropy encoding.

The first embodiment of the invention provides a method for choosing themost effective compression scheme per pixel. A multiplicity ofcompression schemes are utilized and a cost value is associated witheach scheme on a pixel by pixel basis. After associating a cost witheach scheme, the method selects between the most effective or lowestsummed cost scheme on a pixel by pixel basis. The selected schemeprovides a predicted value of the current pixel and an estimate of theprobability that the prediction is correct. The correctness of theestimate, either true or false, is then encoded by an entropy encoderwhich uses the estimated probability to encode the true or false outcomein less than one bit, provided that the estimated probability isaccurate and not in the vicinity of 0.5. Typically, the estimatedprobability is greater than 0.95. In a preferred embodiment, the entropyencoding is performed using an arithmetic encoding process.

In one specific embodiment, one of the compression schemes utilized isreferred to as the "inverse" scheme. The inverse scheme predicts thegray value of a frame buffer pixel. The scheme examines a set ofrecently scanned pixels to define a range within which the pixel underconsideration is likely to fall. The range is determined as follows.

For each previously scanned pixel, the thresholded value and theassociated threshold define a range. For example, if the threshold is150 and the thresholded value is 1, the pre-thresholded value is in therange of 150 to 255. If the thresholded value is 0, the pre-thresholdedvalue is in the range of 0 to 149. The resulting range is intersectedwith the similarly determined range from the next closest neighborpixel.

The intersecting of the threshold matrix ranges continues for eachprevious neighbor pixel until all pixels have been analyzed or untilthere is a contradiction, namely that a range is encountered which hasno common overlap with the most recently calculated range. A valuewithin the most recently calculated range is then selected as anestimate of the value of the pixel under consideration. The differencebetween the corresponding threshold value and the estimated value isthen calculated. Subsequently, a probability table is updated whichrecords the number of times a binary one (1) or zero (0) resulted withthat difference calculation. This probability table is used in theencoding stage.

A second scheme utilized in the specific embodiment above is one similarto that of JBIG, referred to as the "context" scheme. A set of pixels ina frame buffer are selected. Subsequent to the pixel set's thresholding,the thresholded values are concatenated to provide a binary number. Afrequency table is maintained which records the number of times a binaryone (1) or a binary (0) occurs for each sequence of binary numbers forthe pixel set. The concatenated binary number is used as an index intothe frequency table, from which the probabilities for use in theencoding stage are derived.

In the second embodiment of the invention, a hybrid context is formedusing a first number of bits of the hybrid context to store previouspixel information gathered using a first compression scheme, and usingfurther portions of the hybrid context to store previous pixelinformation gathered using other compression schemes. Statistics arestored in a table indexed by the hybrid context, and entropy encoding isperformed based on the probability information in the table indexed bythe hybrid context for the current pixel. The combination of differentprobability determining schemes results in greater probability valuesfor each pixel, and correspondingly higher compression ratios.

In a further specific embodiment, a thirteen bit hybrid context isformed using seven bits to store a quantized gray value differencedetermined using the inverse scheme, and using six bits to storerecently scanned pixel values in the neighborhood in accordance with thecontext (JBIG) scheme. A table, indexed by the hybrid context, is formedcontaining the probability for a given pixel, having the respectivesix-bit JBIG context and the respective seven-bit gray value difference,to be "0" or "1". An entropy encoder encodes the pixel value based onthe prediction and the probability determined from the hybrid context.

BRIEF DESCRIPTION OF THE DRAWINGS

FIG. 1A is a sample table representing a frame buffer.

FIG. 1B is a sample table representing a threshold matrix.

FIG. 1C is a sample table representing the resulting pixel array fromthresholding FIGS. 1A with 1B.

FIG. 2A is a sample table representing a frame buffer with empty cellsto be estimated by the present invention.

FIG. 2B is a sample table representing a threshold matrix which isutilized in predicting the empty cells of FIG. 2A.

FIG. 2C is a sample table representing the resulting pixel array whichis utilized in predicting the empty cells of FIG. 2A.

FIG. 3 is a sample probability table which is utilized in the contextscheme to maintain statistics.

FIG. 4 is a flow diagram demonstrating the switching method of thepresent invention.

FIG. 5 is a flow diagram demonstrating the inverse scheme.

FIG. 6 is a flow diagram demonstrating the process of calculating theg-estimate of an interval.

FIG. 7 is a flow diagram demonstrating the context method.

FIG. 8 is an illustration of one embodiment of a hybrid context.

FIG. 9 is a flow diagram of an encoding process implementing a hybridcontext.

FIG. 10 is a mapping diagram for difference values in one embodiment ofthe invention.

FIG. 11 is a pixel diagram illustrating nearest neighbors for a modifiedJBIG scheme.

FIG. 12 is a threshold diagram for a multi-bit embodiment.

FIG. 13A is a block diagram of a switching embodiment of the invention.

FIG. 13B is a block diagram of a hybrid context embodiment of theinvention.

DETAILED DESCRIPTION OF THE INVENTION

A method and apparatus for compression of data is described. In thefollowing description numerous, specific details, such as the use of thecontext/JBIG and inverse schemes, are set forth in order to provide amore thorough understanding of the present invention. It will beapparent, however, to one skilled in the art, that the present inventionmay be practiced without these specific details. In other instances,well known features have not been described in detail so as not tounnecessarily obscure the present invention.

Current compression methods are comprised of a modeling and an encodingstage. During the modeling stage, the probability that a pixel valuewill be a binary one (1) or zero (0) is estimated. During the encodingstage, this probability is utilized to compress or encode the pixels. Adisadvantage associated with limiting the compression to one modelingscheme is that some schemes work better on data that was originally textand some work better on data that was originally an image.

The present invention overcomes this disadvantage by applying aplurality of different modeling schemes to each pixel. In oneembodiment, the least costly scheme in terms of bits is used to compressthe data. In a second embodiment, each scheme is reduced and combinedinto a single hybrid compression scheme having the advantages associatedwith each of its constituent schemes.

One embodiment of the invention, as illustrated in FIG. 4, provides amethod of selectively switching between the most effective compressionschemes on a pixel by pixel basis. The first step of the switchingmethod is that of choosing a multiplicity of compression modelingschemes which are going to be used 400. In one embodiment of theinvention, a scheme similar to that of JBIG, referred to as the contextscheme, is utilized as one of the schemes in the modeling stage, and the"inverse" scheme is utilized as another scheme in the modeling stage.

Prior to selecting a modeling scheme, a cost value is calculated foreach scheme 404. Thus, the cost for the context scheme and the cost forthe inverse scheme are calculated (see discussion below). The schemewith the lowest summed cost in a pixel neighborhood around the currentpixel is selected 406, and the current pixel is encoded using theselected scheme 408. Subsequent to the encoding, the next pixel to beencoded is selected, and the process is repeated. Such a calculation ofcosts and encoding for each pixel permits the most effective or lowestcost scheme to be utilized to encode each pixel independently.

In the above embodiment, the inverse scheme predicts the gray value of aframe buffer pixel. The inverse scheme, which is discussed more fullybelow, computes a probability that the current pixel is a 0 and aprobability that it is a 1, the two probabilities summing to one. Ifeither probability is high, i.e. close to one, then much less than onebit is required to encode the pixel bit, resulting in compression.

To establish the probability, the inverse scheme predicts the value ofthe current pixel by examining/analyzing its neighboring pixels. Thethreshold ranges of the neighboring pixels are intersected until eitherall of the ranges have been intersected or the ranges cease tointersect. If a neighboring pixel range does not intersect with thepreviously intersected pixel ranges, the previously intersected pixelranges are used as the resulting range. A value within the resultingrange is selected and differenced with the threshold value for the pixelto be estimated. A table is then created which records the probabilitiesthat the true binary value will be a one (1) or a zero (0) based on thedifference value. The probability that a pixel will be a zero (0) or a(1) may be utilized in the encoding stage.

Additionally, in the above embodiment, a scheme similar to that of JBIG,referred to as the "context" scheme, is utilized. A set of pixels in aframe buffer are selected and thresholded. The thresholded values arethen concatenated to provide a binary number. A frequency table iscompiled which records the number of times a binary one (1) or a binary(0) occurs for each sequence of binary numbers. The concatenated binarynumber is used as an index into the frequency table. As a result, thefrequency table maintains the probabilities which may be utilized in theencoding stage. The values in the frequency table may be scaled down atintervals to reduce the storage requirements of the table.

Though various embodiments are described with reference to a "frequency"table, other means for estimating the probability of the current contextmay be used to implement an embodiment of the invention. Typically, anumerical value representative of a statistical history of a context isstored, though the extent of the history may vary for differentembodiments. The probability value and prediction are determinable fromthe numerical value representation, but need not be explicitly presentin the table. Further, the stored numerical value may b e updated (e.g.,as a byproduct of an entropy encoding engine) with each contextoccurrence by increasing or decreasing the respective numerical valuebased on the current pixel prediction and current actual pixel value.

Inverse Compression Scheme

The inverse scheme is a scheme which estimates the probability duringthe modeling stage for later use in the encoding stage of the presentinvention. Referring to FIG. 4, the modeling stage includes steps 400,402, and 404. The encoding stage includes steps 406 and 408. Morespecifically, the compression schemes are utilized after the pixel (p)has been selected 402 and before or as part of the calculation of costs404. The inverse scheme is unique and novel in its approach toestimating the pixel value. The inverse scheme scans the pixel array(P[i][j]) row by row using information from previously scanned pixelsand the threshold array to predict the current pixel.

The estimate of the gray value G₂₄ (FIG. 2A) and the threshold value arethen used to make a prediction, with a probability, as to the value B24.This is derived from the previous occurrences of the arithmeticdifference of the gray estimate and the threshold value.

To perform the estimate, a small set of pixels (S) is utilized, near toP[i][j] that precedes P[i][j] in scan order. Thus, referring to FIG. 5,the first step is the selection of a pixel set 502. In the presentexample, the scan order is from left to right. Thus, the pixels of FIG.2C would be scanned in the following order: P₁₁, P₁₂, P₁₃, P₁₄, P₁₅,P₂₁, P₂₂, . . . , P₄₅, where P_(ij) represents i rows and j columns.Referring again to FIG. 2C, the S-set would likely consist of the valuesscanned prior to the relevant pixel and nearby. The relevant pixel isP₂₄ due to the fact that it corresponds to the location in the G-arraybeing estimated (200). Thus, the S-set would contain: P₁₁ (0); P₁₂ (0);P₁₃ (1); P₁₄ (0); P₁₅ (0); P₂₁ (0); P₂₂ (0); and P₂₃ (1).

For each pixel P[i][j] in the S-set, an estimate of G[i][j] (the valueof the pixel prior to thresholding) may be obtained by knowing whatvalue t was used to threshold G[i][j]. In other words, an estimate ofG₁₁ (of FIG. 2A) may be obtained by knowing that the value 128 (thevalue at T₁₁ of FIG. 2B) was used as the threshold to obtain a binary 0result (the value at P₁₁ of FIG. 2C). Similarly, an estimate of G₂₂ (ofFIG. 2A) may be obtained by knowing that the value 219 (the value at T₂₂of FIG. 2B) was used as the threshold to obtain a binary 0 result (thevalue at P₂₂ of FIG. 2C).

Referring to FIG. 5, after selecting a set of neighboring pixels 502, apixel that has not been previously selected (NP) is selected from thepixel set (S) 504. Referring to FIG. 2A, a pixel such as G₂₃ would beselected to begin the estimation. If this is the first pixel to beselected 506, then a first interval level must be set. Setting the firstinterval level consists of first determining whether or not the binarythresholded value (BTV) of the pixel (NP) is equal to zero (0) or one(1)508. If the binary thresholded value (BTV) is equal to zero (0), thenthe value of the pixel (NP) may be assumed to be lower than thethreshold level 510. Conversely, if the binary thresholded value (BTV)is equal to one (1), then the value of the pixel (NP) may be assumed tobe higher than or equal to the threshold level 512. Thus, assuming, asin the preferred embodiment, that the pixel values are made up of 8 bits(256 different values), the minimum value is that of zero (0) and themaximum value is that of 255.

The following equations set forth what the range of G[i][j] (NP) isdepending on the resulting binary thresholded value (BTV):

    t≦G[i][j]≦255, if the BTV of P[i][j]=1

    0≦G[i][j]<t, if the BTV of P[i][j]=0

If the binary thresholded value (BTV) at P[i][j] is equal to 1, then itmay be inferred that the value at G[i][j] is greater than or equal tothe t-value which was used in G[i][j]'s (NP's) thresholding. Similarly,if the binary thresholded value (BTV) at P[i][j] is equal to 0, then itmay be inferred that the value at G[i][j] is less than the t-value whichwas used in G[i][j]'s thresholding.

For example, if the binary thresholded value (BTV) at P[i][j] was equalto a binary 1 and the threshold level (T[i'][j']) is equal to 200, thenit may be inferred that the value at G[i][j] is equal to or greater than200. Similarly, if P[i][j] is equal to a binary 0 and the thresholdvalue (T[i'][j']) is equal to 200, then it may be inferred that thevalue at G[i][j] is less than 200. Referring to FIG. 2C, the binarythresholded value (BTV) at P₁₃ is 1. The value which was used as athreshold was 101 (the value at T₁₃ of FIG. 2B). As a result, it can beestimated that the value of G₁₃ (NP) of FIG. 2A is greater than or equalto 101. Similarly, the binary thresholded value of P₂₂ (of FIG. 2C) is0. The value which was used as a threshold for P₂₂ was 219 (the value atT₂₂ of FIG. 2B). Consequently, it may be inferred that the value at G₂₂(NP) is less than 219. Although the above examples of FIG. 2 demonstratethat the values of G₁₃ and G₂₂ are already known (147 and 205respectively), to utilize the inverse scheme of the present invention,estimates of all pixels in an S-set must be performed.

Based on the estimates of the surrounding pixels, the inverse schemeestimates the desired value at G[i][j] (200). To make the estimation ofX at G[i][j] (200), the intervals for each of the pixels in S areintersected. Hence, referring again to FIG. 5, subsequent to the firstpixel 506, the intervals associated with the remaining pixels (NP) inthe pixels set (S) are intersected. The intersections are performedsequentially in order of proximity to pixel p. Thus, the intervalsassociated with the pixels from the S set are intersected one at a timebeginning with the pixel closest to pixel p. Referring to FIG. 2A, ifpixel X 200 is the pixel to be estimated and the first pixel to beanalyzed is that of G₂₃ (with a value of 234), the next pixel that wouldhave been scanned is that of G₂₂ (with a value of 205). The next pixelthat would have been scanned is that of G₂, then G₁₅, etc.

Referring again to FIG. 5, the first step of intersecting is that ofdetermining the binary thresholded value of the pixel which is currentlybeing analyzed/intersected 514. If the binary thresholded value is zero(0), then once again, it is known that the value prior to thresholdingwas less than the threshold value (T). Hence, the maximum value of thepixel (NP) would be that of one less than the threshold value. Forexample, the binary thresholded value of P₂₂ (NP) (of FIG. 2C) is 0. Thevalue which was used as a threshold for P₂₂ was 219 (the value at T₂₂ ofFIG. 2B). Consequently, it may be inferred that the value at G₂₂ (NP) isless than 219 or the maximum value of NP is one less than 219 or 218.Hence, NP has a range of from 0 to 218.

Similarly, if the binary thresholded value is equal to one (1), thenonce again, it is known that the value prior to thresholding was greaterthan or equal to the threshold value (T). Hence, the minimum value ofthe pixel (NP) would be that of the threshold value. For example,referring to FIG. 2C, the binary thresholded value (BTV) at P₁₃ is 1.The value which was used as a threshold was 101 (the value at T₁₃ ofFIG. 2B). As a result, it can be estimated that the value of G₁₃ (NP) ofFIG. 2A is greater than or equal to 101. Hence, the minimum value of thepixel (NP) would be that of 101.

If the intersection of the intervals as already determined does notintersect with the current NP's range, the process stops. As a result,it must be determined if an intersection will occur at all (steps 516and 518 of FIG. 5). If the existing interval level is greater than thethreshold level, and the binary thresholded level was a zero (0), thenthe ranges do not intersect 516. For example, if the BTV is zero (0),the existing interval level is from 210 to 255, and the threshold levelis a 200, then the ranges 0-199 and 210-255 do not intersect. As such,the process stops without including the current NP's range in theintersection.

Similarly, if the existing interval is less than the threshold level,and the binary thresholded level was a one (1), then the ranges do notintersect 518. For example, if the BTV is one (1), the existing intervallevel is from 0 to 150, and the threshold level is a 200, then theranges 0-150 and 200-255 do not intersect. As such the process stops. Onthe other hand, assuming that an intersection will occur, then theexisting interval level is updated, restricting the interval to therange of the intersection (Steps 520, 522, and 524 of FIG. 5). Forexample, if the range for some pixel A (a pixel in closest proximity topixel p) was greater than or equal to 200 (200-255), and the range forsome other pixel B (the pixel in next closest proximity to pixel p) wasless than 210 (0-210), the intersection of the two intervals is from 200to 210.

The intersection of the ranges in close proximity to pixel p thencontinues. Continuing with the above example, the intersection 200-210would then be intersected with the next previous pixel in the scan.Referring to FIG. 2, assuming that the S-set consists of the nearest 7pixels as discussed supra, to estimate the value of X 200, the intervalsfor the pixels in the S-set (those in closest proximity to X) areestimated and intersected. Thus, the first pixel to be estimated is thatof G₂₃. To estimate what G₂₃ would be, its binary thresholded value(BTV) and its threshold value are examined. The binary thresholded value(BTV) of P₂₃ is 1 and the threshold value is 197. Thus, it may beestimated that G₂₃ must be greater than or equal to 197. Due to the factthat the pixels in FIG. 2 are made up of 8 bits, the maximum value is255. Hence, the interval for G₂₃ is from 197-255.

The next pixel in closest proximity is that of G₂₂. The binarythresholded value (BTV) of P₂₂ is 0 and the corresponding thresholdlevel at T₂₂ is 219. Therefore, the estimated value for G₂₂ must belower than 219. The intersection of the intervals from G₂₃ and G₂₂ isthen calculated. G₂₂ ranges from 0 to 218 and G₂₃ ranges from 197-255.Therefore, the intersection must be lower than 218 but higher than 197.Such an intersection results in an interval from 197-218. This processis then repeated with the next pixel in the closest proximity to X 200.

The intersection of the intervals continues until one of two conditionshas been met. The first condition occurs when all of the intersects ofpixels in the S-set have been intersected ("Condition A") (526). Thesecond condition occurs when the intersection results in an empty set(i.e. the threshold intervals did not intersect) ("Condition B") (516and 518), in which case the previous non-empty intersection is examined.

Continuing with the example above, the next closest pixel is that ofG₂₁. The binary thresholded value (BTV) at P₂₁ is 0 and the thresholdlevel at T₂₁ is 111. Thus, the value of G₂₁ must be less than 111. Theintersection of this interval with the above interval (197-218) resultsin a set which is between 0 and 111 and also between 197-218. Due to thefact that no such value exists, the two intervals do not intersectresulting in a "contradiction". As a result, "Condition B" has been met(the threshold intervals did not intersect). The intersection of theintervals process comes to a halt. The last intersection whichmaintained a value is preserved (197-218).

From the resulting intersection interval, a value is estimated(g-estimate) and selected for G[i][j] (pixel p). Referring to FIG. 6, if"Condition A" has been met 602A, then the midpoint of the resultingintersection is used as the g-estimate 604. Thus, if all pixels areintersected, condition A is met and the midpoint is used. In the aboveexample, if no contradiction had resulted and all of the pixel intervalshad been intersected, the midpoint between 197 and 218 (the value 208)would be used as the g-estimate. If "Condition B" has been met 602B,then the value closest to the contradiction is utilized (Steps 606, 608,and 610). Thus, if pixel intervals do not intersect, condition B is metand an endpoint is used.

In the above example, the resulting intersection interval is from197-218. Further, the contradiction and halting arose with a value of111 (Step 606A of FIG. 6). Therefore, the value closest to thecontradiction, yet still within the interval is that of 197, which isthen used as the g-estimate 608. If the contradiction had occurred witha non intersecting interval of 230-255 (Step 606B of FIG. 6), then theendpoint of 218 would be used as the g-estimate because it is theclosest value to the contradiction (230) (Step 610 of FIG. 6).

The first step in estimating the current pixel probability isobtaining/computing a difference value. The difference value (diff) isthe difference between the g-estimate for pixel p and the thresholdvalue (T) for pixel p. Thus, diff equals the g-estimate minus T[i'][j']where T[i'][j'] is the threshold value for the pixel at P[i][j]:

    diff=g-estimate-T[i'][j']

Once again continuing with the above example, the value 197 is theg-estimate. Diff is therefore equal to 197-T[i'][j']. T[i'][j'] in thepresent example is equal to 214 (the value at T₂₄ 220). Thus, diff isequal to 197=214 or -17.

The value of diff is used as the context for obtaining an estimatedprobability from a table comprising statistical history information foreach context. For eight-bit g-estimates and threshold values, diff mayretain values in the range: -255, -254, . . . , 253, 254.

(g values in 0, 1, . . . 255 t values in 1, . . . , 255)

The current pixel bit value and the associated diff value context may beused to update the statistical information in the table.

In one embodiment, statistics are maintained on the approximate numberof times previously for each diff value that P[i][j] has resulted in abinary 0 after thresholding and the number of times P[i][j] has resultedin a binary 1 after thresholding. Thus, a table indexed by the diffvalue context may be created which maintains approximate statisticalinformation gathered over a number of past pixels.

For example, if for seven out of 10 times when the diff value was a -4,P₁₂ was a 0, and for three out of those ten times P₁₂ was a 1, suchfrequencies/statistics or approximations thereof would be recorded.Based on this frequency, prob₁ may be estimated. Prob₁ is equal to theestimated probability that the pixel is a binary 1. Therefore, as in theabove example, if for the last three out of ten times when the diffvalue was a -4, prob₁ would retain the value of approximately 3/10 or0.3. Prob₀ is equal to the estimated probability that the pixel is abinary 0. Similarly, if for the seven of the last ten times when thediff value was a -4, P₁₂ was a 0, prob₀ would retain the value ofapproximately 7/10 or 0.7. It should be noted that the total of theprobabilities is 1:

    prob.sub.0 +prob.sub.1 =1

    7/10+3/10=1.

Thus, both probabilities need not be estimated in all embodiments, asone probability may be determined from the other.

As previously stated, the "frequency" table implementation forestimating probabilities is one example of how probability informationmay be determined for each context. Other methods for estimating theprobability associated with each diff value context may also be usedwithin the scope of the invention.

Context Compression Scheme

A second scheme used in some embodiments of the invention is a variationof the JBIG scheme described above. Referring to FIG. 7, the pixels in Sor a similar set are utilized (802). The binary thresholded values (BTV)are concatenated to provide a binary number which is then used as anindex into a table of frequency counts (804). The estimated probabilitytable is compiled from each previous occurrence of the index (context)(806). This method is referred to as the context method. Hence, if thecontext is from 4 pixels, a table such as in FIG. 3 is maintained andutilized to retain statistics of prob₁ or prob₀ in the context/JBIGscheme.

Referring to the table, the probability that the next bit after 1011would be a 1 is examined by looking to the appropriate location of thetable at 1011 signified by 300. Thus, the table indicates that 4/10 or 4out of the last 10 times, the next bit was a 1. Similarly, theprobability that the next bit after 1101 would be a 1 is examined bylooking to the appropriate location of the table at 1101. Thus, thetable indicates that 8/13 or 8 out of the last 13 times, the next bitwas a 1. The table may also contain approximations rather than exactvalues. After each pixel is encoded, the table is updated to record theappropriate statistics.

Switching Method

The generation of a context (e.g., a diff value or a JBIG-type context)and assigning of a probability to the context is the modeling portion ofthe compression. Thus, the inverse scheme and context scheme comprisethe modeling portion of an embodiment of the invention. If theprobabilities are accurate and close to 1, high compression is achieved.In other words, the more accurate the probabilities are and closer to 1(or 10 out of 10 times; or 7/7 times . . . ), the higher thecompression.

In some embodiments, an entropy encoder may update the prediction andprobability data in a feedback arrangement. Modeling may thus beperformed during the encoding process by an adaptive encoder. Forexample, if a certain context and bit value are occurring with greaterfrequency, the estimated probability for that context may be adjustedupwards if the prediction matches the actual bit value, or downwards ifthe prediction does not match the actual bit value.

The portion of compression which involves conversion of the prediction,the estimated probability, and the actual bit value into encoded bits iscalled entropy encoding. Entropy is a term of art which means or is ameasure of how much information is encoded in a symbol. Thus, the higherthe entropy of a message, the more information it contains. In thisrespect, if one uses entropy encoding, bits of data may be encoded usinga number of bits corresponding to their information content. Verypredictable bits have a lower entropy, so require fewer bits to encode.

As the probability of a certain bit increases, the compression obtainedusing entropy encoding increases. Thus, the objective is to use a schemewhich results in the highest probability for each pixel. Therefore, thebest possible entropy encoding would use the highest probability asobtained from various different schemes (e.g., the inverse scheme, theJBIG scheme, etc.). The switching method of the present invention allowsfor bit-level selective switching from scheme to scheme to utilize thehighest probability.

The information regarding the pixels prior to P[i][j] (and the thresholdarray) is referred to as the context: ##EQU2## In this respect, theprobability that P[i][j] is equal to 1 is prob₁ and the probability thatP[i][j] is equal to 0 is prob₀. Thus, using the context scheme andreferring to FIG. 3, the estimated probability, prob₁, that P[i][j] willhave a binary value of 1 (300) is approximately 4/10 or 0.4 and theestimated probability, prob₀, that P[i][j] will have a binary value of 0is approximately 1-prob₁ or 1-0.4=0.6 or 6/10.

Using arithmetic encoding (a type of entropy encoding), the higher theprobability, the higher the compression capability. In order todetermine the number of bits which are required to encode a set ofbinary numbers, the probability is used in a logarithmic calculation.More specifically, the number of bits required to encode a binary numberwith a known probability is: ##EQU3## Thus, compression will take placeaccording to the above statistics using arithmetic encoding.

If prob₁ is an accurate reflection of the true probability, the expectedcost in encoding bits to encode P[i][j] is given by: ##EQU4##

To keep this cost low, the estimate of prob₁ needs to be accurate and asclose to 0 or 1 as possible. As the estimate of prob₁ moves away from0.5, the number of bits required to encode the respective pixel bitdecreases. This results due to the fact that if prob₁ is near 0 (i.e.,prob₀ is near 1), then the number of bits required to encode that bit isclose to 0. Similarly, if prob₁ is near 1, then the number of bitsrequired to encode that bit is also close to 0. Thus, the closer theprobability is to 0 or 1, the lower the cost of encoding is.

The probability prob₁ is a conditional probability, conditioned on thecontext used. In the embodiment described herein, two different contexts(schemes) are utilized and whichever context (scheme) results in thelowest total cost over a set of previously encoded pixels is the schemeused for encoding the current bit. In other embodiments, more than twoschemes may be cost-evaluated for encoding each pixel bit.

At each previously scanned pixel, the cost to encode that pixel iscomputed as: ##EQU5## if the pixel was a one. Similarly, -log₂ prob₀^(inverse) and -log₂ prob₀ ^(context) if the pixel was a zero, whenprob_(i) ^(inverse) and prob_(i) ^(context) are the probabilityestimates from the inverse and context schemes.

The next step is to add up the cost for the set of previously encodedpixels, such as S, for each scheme. The scheme with the lower sum isused to predict P[i][j]. In other words, the scheme with the lowersummed cost is utilized for the encoding. Thus, if the summed cost ofthe inverse scheme over the pixel set S is 140 bits and the summed costof the context scheme over the pixel set S is 165 bits, then the inversescheme would be utilized for the encoding. The summed cost isrecalculated for each new pixel scanned in the P[i][j] array. Hence, thescheme used may be switched from pixel to pixel depending on the costassociated with each scheme.

FIG. 13A is a functional block diagram illustrating a switchingembodiment of the invention. In FIG. 13A, scanned data is stored inregisters (e.g., a shift register) or memory cells 1500 for use inencoding the data. The neighboring pixel bit values 1505 of the set Sfrom registers 1500 are provided to the multi-scheme context/indexgenerator 1501. Contexts or indices 1506 are generated for each schemeusing methods such as those described for the inverse and JBIG schemes.

Contexts and indices (such as diff and the JBIG context) 1506 arepresented to the statistics/probability tables 1502 to access therespective stored predictions and probabilities 1507 for each scheme.The prediction/probability values 1507 are provided to the cost analysisswitcher/selector 1503 for determination of the current encoding scheme,based on the cost analysis described above. The prediction/probability1508 for the selected scheme is then provided to entropy encoding engine1504. The current pixel bit value 1509 from registers 1500 is alsoprovided to entropy encoding engine 1504, and based on the value ofprediction/probability 1508, entropy encoding engine 1504 producesencoded data 1510.

The functional blocks of FIG. 13A may be embodied in dedicatedelectronic hardware, or they may be embodied in software functionsimplemented in general electronic hardware, or they may be embodied in acombination of dedicated hardware and software functions.

Hybrid Context Method

A second embodiment of the invention utilizes multiple compressionschemes to form a hybrid context for each pixel. By using a hybridcontext, the embodiment is able to take advantage of the uniquestatistical aspects of each compression scheme in determining theprobability for each possible hybrid context. The resulting hybridcontext can provide improved prediction ability (i.e., higherprobabilities) with correspondingly higher compression ratios.

The hybrid context is formed by assigning a portion of bits in thecontext to each compression scheme. The size of the total context andthe apportionment of the bits between the respective schemes may varyfor different embodiments. For the purpose of clarity, a specificembodiment having a two-scheme thirteen-bit context is described.

In this embodiment, the thirteen-bit context is separated into aseven-bit portion assigned to the inverse scheme, and a six-bit portionassigned to an abbreviated JBIG scheme. This apportionment isillustrated in FIG. 8. As shown, the six least significant bits (B6-B1)of the thirteen-bit context store the JBIG context information, and theseven most significant bits (D6-D0) store the inverse schemeinformation. Similar embodiments may have a different ordering of thiscontext information.

The set of previous pixels S' is a reduced set from S described earlier.The set S' consists of six previous pixel values as shown in FIG. 11. B0represents the current pixel, whereas B1-B6 represent the six nearestneighbors, with B1 being the nearest neighbor, B2 being the secondnearest neighbor, etc. The values of B1-B6 provide the abbreviated JBIGcontext portion for the hybrid context.

With respect to the inverse scheme context portion, the "gray value"estimation is performed as described previously for the inverse schemeby progressing through the respective ranges of the previous pixelvalues, preferably in the order of B1, B2, B3, etc., to maintain thepriority of the nearest pixels since the nearest pixels contain thehighest predictive information. In other embodiments, to reduce theamount of calculation per pixel, the "gray value" range for severalpixels may be precalculated by column and stored to render repeatedcalculation of the intersections unnecessary. The calculation reductionis achieved with some compromise in priority of the pixel information.

The resulting difference value (diff) between the gray value estimateand the current pixel threshold is typically within the range of -255 to254, e.g., for eight-bit pixel data. In order to reduce this differencevalue into the prescribed seven bits, the difference value is remappedinto the range of 0 to 127. One such mapping is illustrated in FIG. 10.

In FIG. 10, the difference value (diff) is mapped into the seven bitdifference value (diff') for generation of the inverse scheme portion ofthe hybrid context as follows: ##EQU6## The above distribution for diff'assures better probability resolution for gray value estimates near thethreshold value at the cost of clamping diff' for gray value estimatesfurther away from the threshold, where the probability is less likely tovary substantially for different diff values.

With the hybrid context formed as described, statistical analysis of aset of past data may be performed to establish a probability tableindexed by specific context values for use in the entropy encoding. Asdescribed previously, this may be done by tracking the number ofoccurrences of each particular context, and the number of times eachparticular context resulted in a "1" or a "0." The resulting probabilityfor a particular context to yield a "1," for example, would then be anapproximate count of times that particular context produced a "1"divided by the overall approximate count for occurrences of thatparticular context. Also, as mentioned previously, an adaptive entropyencoder may update statistics during encoding to maintain probabilitydata, or some combination of statistical analysis and adaptive encodingmay be used.

FIG. 9 is a flow diagram for the encoding process using the hybridcontext. In step 1100, the six-bit JBIG context is determined from sixprevious pixels. In step 1101, the seven-bit inverse scheme context(diff') is determined. The relative order in which steps 1100 and 1101are performed is not critical to the operation of the embodiment. Instep 1102, the two context portions are combined into a single hybridcontext, and, in subsequent step 1103, the context is used as an indexinto the statistics table to obtain the prediction and estimatedprobability for that context. In step 1104, the prediction, estimatedprobability and actual current bit value are provided to an entropyencoder for encoding of the current bit.

On the decoding side, an entropy decoder will receive the encoded bit.By performing similar operations to steps 1100-1104, the hybrid contextis formed and applied to the same or a similar statistics table toobtain the prediction and probability. The entropy decoder is thus ableto decode the current bit value.

FIG. 13B is a functional block diagram illustrating a hybrid contextembodiment of the invention. In FIG. 13B, scanned data is stored inregisters (e.g., a shift register) or memory cells 1500 for use inencoding the data. The neighboring pixel bit values 1505 (e.g., from theset S or S') from registers 1500 are provided to the multi-schemecontext/index generator 1501. Contexts or indices 1506 are generated foreach scheme using methods such as those described for the inverse andJBIG schemes.

Contexts and indices (such as diff or diff' and the JBIG context) 1506are provided to hybrid context generator 1511 to be combined into hybridcontext 1512. Hybrid context 1512 is presented to thestatistics/probability table 1502 to access the respective storedprediction and probability 1508 for the hybrid context scheme. Theprediction/probability 1508 for the current hybrid context is thenprovided to entropy encoding engine 1504. The current pixel bit value1509 from registers 1500 is also provided to engine 1504, and based onthe value of prediction/probability 1508, engine 1504 produces encodeddata 1510.

The functional blocks of FIG. 13B may be embodied in dedicatedelectronic hardware, or they may be embodied in software functionsimplemented in general electronic hardware, or they may be embodied in acombination of dedicated hardware and software functions.

Entropy/Arithmetic Encoding

The present invention permits the selective switching of compressionschemes based on cost analysis, or the combining of compression schemesin a hybrid context. The objective is to represent the pixel array infewer bits than n rows by m columns.

The encoding stage of the invention utilizes the probabilities obtainedin the modeling stage to encode the bits such that they are representedin fewer bits. This is performed through entropy encoding. In anembodiment of the present invention, the method of arithmetic encodingis utilized to perform entropy encoding.

The above description has focused on the compression of image datacompressed (thresholded) into one-bit data which is then furthercompressed by the methods of the invention. It will be obvious to thoseskilled in the art that the methods of the invention may be similarlyapplied to multi-bit data. For example, data may be thresholded as shownin FIG. 12 such that two-bit data is the result. Rather than onethreshold value for each pixel, three threshold values are provided foreach pixel to divide the initial pixel value range into four sections,each section represented by a two bit value (00, 01, 10, 11).

Multi-bit schemes may be encoded on a bit by bit basis. Bitwise encodingmay be performed by designating bit-planes for the data, such as a mostsignificant bit-plane and least significant bit-plane. Each bit plane isthen encoded using the bi-level data schemes described above, thoughlesser bit-planes may take advantage of the predictive information inthe more significant bits by using nearest neighbor sets including bitsin adjacent bit-planes.

Magnitude code representations may be used to permit encoding ofsubsequent bits based on the encoding of the previously encoded bits ofa pixel. For example, if the three-bit magnitude code values 000, 001,011 and 111 are assigned to the two-bit pixel values 00, 01, 10 and 11,then the second bit need be encoded only if the most significant bit isa zero, and likewise, the least significant bit need be encoded only ifthe second bit is zero. Thus, multi-bit compression may be performedusing the methods of the present invention.

Thus a method and apparatus for data compression has been described inconjunction with one or more specific embodiments. The invention isdefined by the claims and their full scope of equivalents.

I claim:
 1. A scheme for predicting a gray value of a frame buffer cellcomprising the steps of:selecting a pixel-set (S) from previouslyscanned pixels in a pixel array; intersecting intervals from pixels inthe pixel-set, said intersecting process comprising the stepsof:determining an interval (I) from a first pixel in the pixel-set;determining a pixel-interval (PI) from another pixel in the pixel-set;intersecting said interval (I) with said pixel interval (PI) to create anew interval (NI) if NI is not an empty set, adjusting I to equal NI;and selecting a gray value from the interval (I) wherein said pixelinterval (PI) is greater than or equal to a threshold value if acorresponding binary threshold pixel value is
 1. 2. The scheme of claim1 wherein said pixel-set (S) is constructed from pixels closest inproximity to the pixel of the frame buffer cell being predicted.
 3. Thescheme of claim 1 wherein said step of intersecting intervals isconducted in order of proximity to the pixel of the frame buffer cellbeing predicted.
 4. The scheme of claim 1 wherein said pixel interval(PI) is less than a threshold value if a corresponding binarythresholded pixel value is
 0. 5. The scheme of claim 1 wherein said grayvalue is a midpoint of the interval (I) if NI does not contain the emptyset.
 6. The scheme of claim 1 wherein said gray value is an endpoint ofthe interval (I) if NI is an empty set.
 7. The scheme of claim 6 whereinsaid endpoint is the endpoint closest to the pixel-interval (PI).
 8. Thescheme of claim 1 further comprising the step of:comparing said grayvalue to a threshold matrix value.
 9. The scheme of claim 8 furthercomprising the steps of:forming a difference value from said comparingstep; and utilizing said difference value as a pixel context.
 10. Thescheme of claim 9 wherein said step of utilizing said difference valuecomprises the steps of:accessing statistical information indexed by saiddifference value; and performing entropy encoding using said statisticalinformation.
 11. An apparatus for predicting a gray value of a framebuffer cell comprising:means for intersecting intervals from pixels in apixel-set (S) selected from previously scanned pixels in a pixel array,said intersecting means comprising:means for determining a resultinginterval (RI) from a first pixel in the pixel-set; means for determininga pixel-interval (PI) from another pixel in the pixel-set; means forintersecting said resulting interval (RI) w;th said pixel internal (P₁)to create a new interval (NI) means for adjusting RI to equal NI, if NIis not an empty set; and means for selecting a gray value from theresulting interval (RI) wherein said pixel interval (PI) is greater thanor equal to a threshold value if a corresponding bi-level pixel valueis
 1. 12. The apparatus of claim 11 wherein said pixel-set (S) comprisespixels closest in proximity to the pixel of the frame buffer cell beingpredicted.
 13. The apparatus of claim 11 wherein said means forintersecting intervals comprise means to intersect in order of proximityto the pixel of the frame buffer cell being predicted.
 14. The apparatusof claim 11 wherein said pixel interval (PI) is less than a thresholdvalue if a corresponding bi-level pixel value is
 0. 15. The apparatus ofclaim 11 wherein said gray value is a midpoint of the resulting interval(RI) if NI is not an empty set.
 16. The apparatus of claim 11 whereinsaid gray value is an endpoint of the resulting interval (RI) if NI isan empty set.
 17. The apparatus of claim 16 wherein said endpoint is theendpoint closest to the pixel-interval (PI).
 18. The apparatus of claim11 further comprising:means for comparing said gray value to a thresholdmatrix value.
 19. The apparatus of claim 18 further comprising:means forapplying a difference value generated from said comparing means as apixel context.
 20. The apparatus of claim 19 wherein said applying meanscomprises:means for accessing statistical information indexed by saiddifference value; and an entropy encoder receiving said statisticalinformation.